package cn.stylefeng.guns.modular.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.modular.dto.FuzzySearchSFormDto;
import cn.stylefeng.guns.modular.entity.ScheduleForm;
import cn.stylefeng.guns.modular.mapper.ScheduleFormMapper;
import cn.stylefeng.guns.modular.service.ScheduleFormService;
import cn.stylefeng.roses.core.datascope.DataScope;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
public class ScheduleFormServiceImpl implements ScheduleFormService {
    @Resource
    private ScheduleFormMapper scheduleFormMapper;

    /**
     * 根据用户id查询所有日程表
     * @return
     */
    public List<ScheduleForm> selectAllScheduleForm(long userId){
        return scheduleFormMapper.selectAllScheduleForm(userId);
    }

    /**
     * 根据用户id查询
     * @return
     */
    public List<ScheduleForm> selectById(long userId){
        return scheduleFormMapper.selectById(userId);
    }

    /**
     * 根据日程表id查询日程表
     * @param sformId
     * @return
     */
    public ScheduleForm selectSformBySformId(int sformId){
        return scheduleFormMapper.selectSformBySformId(sformId);
    }

    /**
     * 根据关键信息进行模糊查询日程表
     * @param fuzzySearchSFormDto
     * @return
     */
    public Page<Map<String, Object>> fuzzySearchSForm( FuzzySearchSFormDto fuzzySearchSFormDto,long userId){
        Page page = LayuiPageFactory.defaultPage();
        System.out.println("==========================="+page);

        return scheduleFormMapper.fuzzySearchSForm(page,fuzzySearchSFormDto,userId);
    }

    /**
     * 根据日程表全名称进行准确查询
     * @param sfromName
     * @return
     */
    public ScheduleForm selectScheduleFormByAllName(String sfromName,long userId){
        return scheduleFormMapper.selectScheduleFormByAllName(sfromName,userId);

    }

    /**
     * 保存日程表
     * @param scheduleForm
     * @return
     */
    public int saveScheduleForm(ScheduleForm scheduleForm){
        return scheduleFormMapper.saveScheduleForm(scheduleForm);
    }

    /**
     * 根据日程表id删除日程表
     * @param sformId
     * @return
     */
    public int deletScheduleFormBy(int sformId){
        return scheduleFormMapper.deletScheduleFormBy(sformId);
    }


    /**
     * 首页显示两个日程表
     * @return
     */
    public  List<ScheduleForm> showLimitTwo(long userId){
        return scheduleFormMapper.showLimitTwo(userId);
    }

    /**
     *
     * 保存修改信息
     * @param sformName 表名
     * @param draft 是否保存为草稿
     * @param sformId 表Id
     * @return
     */
    public int updateSform(String sformName,String draft,int sformId){
        return scheduleFormMapper.updateSform(sformName,draft,sformId);
    }

    /**
     * 修改日程表的共享状态
     * @param share
     * @param sformId
     * @return
     */
    public int setSformShare(@Param("share") String share,@Param("sformId") int sformId ){
        return  scheduleFormMapper.setSformShare(share,sformId);
    }


    /**
     * 查询该用户的所有草稿日程表
     * @param userId
     * @return
     */
    public List<ScheduleForm> showAllDraftSform(@Param("userId") long userId){
        return scheduleFormMapper.showAllDraftSform(userId);
    }

    /**
     * 模糊查询草稿日程表
     * @param keyword
     * @param creatTime
     * @return
     */
    public Page<Map<String, Object>> fuzzyShowDraftSform( @Param("keyword") String keyword,@Param("creatTime") String creatTime){

        Page page = LayuiPageFactory.defaultPage();
        System.out.println("==========================="+page);
        return  scheduleFormMapper.fuzzyShowDraftSform(page,keyword,creatTime);
    }



}
